<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "user_patient".
 *
 * @property int $id
 * @property int $user_id 用户id
 * @property string $patient 患者
 * @property string $age 年龄(开药方时根据开方时期显示更新的年龄)
 * @property int $sex (0女 1男)
 * @property string $site 地址
 * @property string $card 证件(新农合)
 * @property string $create_time 操作日期
 * @property int $status 状态
 *
 * @property User $user
 * @property UserPatientSymptom[] $userPatientSymptoms
 * @property UserPatientSymptom[] $userPatientSymptoms0
 */
class UserPatient extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'user_patient';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['user_id', 'patient'], 'required'],
            [['user_id', 'sex', 'status'], 'integer'],
            [['create_time'], 'safe'],
            [['patient'], 'string', 'max' => 100],
            [['age'], 'string', 'max' => 10],
            [['site', 'card'], 'string', 'max' => 255],
            [['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['user_id' => 'id']],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'user_id' => '用户id',
            'patient' => '患者',
            'age' => '年龄',
            'sex' => '性别',
            'site' => '地址',
            'card' => '证件(新农合)',
            'create_time' => '操作日期',
            'status' => '状态',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getUser()
    {
        return $this->hasOne(User::className(), ['id' => 'user_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getUserPatientSymptoms()
    {
        return $this->hasMany(UserPatientSymptom::className(), ['user_patient_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getUserPatientSymptoms0()
    {
        return $this->hasMany(UserPatientSymptom::className(), ['user_patient_id' => 'id']);
    }
}
